﻿using System.Xml.Serialization;

namespace eProject.Model
{
    [XmlRoot("Employee")]
    public class Employee
    {
        [XmlAttribute]
        public string Email
        {
            get{ return _email;} 
            set
            {
                if (value == _email) return;
                _email = value;
                InvokeEmailChanged(this, _email);
            }
        }

        [XmlAttribute]
        public string Name{ get; set;}

        [XmlAttribute]
        public string Surname { get; set; }

        [XmlAttribute]
        public string PhoneNumber { get; set; }

        public Employee(string name, string surname, string email, string phonenumber)
        {            
            Name = name;
            Surname = surname;
            Email = email;
            PhoneNumber = phonenumber;
        }

        public Employee()
        {
            
        }

        private string _email;

        internal event EventHandler<Employee,string> EmailChanged;

        private void InvokeEmailChanged(Employee item, string oldEmail)
        {
            var changed = EmailChanged;
            if (changed != null) changed(item, oldEmail);
        }
    }
}
